package com.hdaccp.shuiguoD.controller;

import com.hdaccp.shuiguoD.entity.Gongying;
import com.hdaccp.shuiguoD.service.GongyingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/info1")
@Scope("prototype")
public class GongyingController {

    @Autowired
    private GongyingService gongyingService;

    @RequestMapping("/queryAll")
    @ResponseBody
    public Map<String,Object> queryAll(int offset,int limit){
        /* Map<String,Object> map = new HashMap<>() ;
        map.put("rows",userInfoService.findAll(offset,limit)) ;
        map.put("total",userInfoService.findTotalCount()) ;
        return  map ;*/

        return null;
    }

   /* @RequestMapping("queryAll")
    @ResponseBody
    public List<Gongying> queryAll(){
        return gongyingService.getAll();
    }*/

    @RequestMapping("/querySearch")
    @ResponseBody
    public Map<String,Object> querySearch(String gname, int offset, int limit){
        Map<String,Object> map = new HashMap<>();
        map.put("rows",gongyingService.findAll(gname,offset,limit));
        map.put("total",gongyingService.findTotalCount(gname));
        return map;
    }

    @RequestMapping("/shanchu")
    @ResponseBody
    public int shanchu(int gid){
        return gongyingService.delte(gid);
    }

    @RequestMapping("/inst")
    @ResponseBody
    public int inst(Gongying gongyinginfo){
        return gongyingService.zj(gongyinginfo);
    }

    @RequestMapping("/xg")
    @ResponseBody
    public int xg(Gongying gongyinginfo){
        System.out.println(gongyinginfo.getGid()+"---");
        return gongyingService.update(gongyinginfo);
    }

    /**
     * 根据ID查询
     * @param gid
     * @return
     */
    @RequestMapping("/queryById")
    @ResponseBody
    public Gongying queryById(int gid){
        return gongyingService.queryById(gid);
    }
}
